import { Injectable } from '@angular/core';
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';

import { map } from "rxjs/operators";

@Injectable()
export class DynamicFormValueService {

    constructor(private http: HttpClient) { }

    /**
     * 保存或更新表单信息
     * @param value 表单Json数据
     */
    saveUpdateFormValue(value: any) {
        return this.http.post('/form/api/value/saveupdatevalue', value, {
            headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' })
        }).pipe(
            map((res: Response) => res['data'])
        );
    }

    /**
     * 加载表单值
     */
    loadFormValue(value: any) {
        return this.http.post('/form/api/value/loadvalue', value).pipe(
            map((res: Response) => res['data'])
        );
    }
}
